#include <stdio.h>
#include "engine.h"

chess::Engine engine;

int main(int argc, char** argv) {
	printf("Chess demo...\n");

	engine.startup(1);
	for (;;) {
		int state = engine.getState(nullptr);
		if ((state & 3) || (state & 4) || (state & 5)) {
			printf("Game over! ");
			if (state & 3) {
				printf("Red win! \n");
			} else if (state & 4) {
				printf("Black win! \n");
			} else {
				printf("Drawn! \n");
			}
			break;
		}
		int x1, y1, x2, y2;
		if (engine.findSolution(1, x1, y1, x2, y2)) {
			printf("Find solution: %d,%d to %d,%d\n", x1, y1, x2, y2);
			if (engine.move(x1, y1, x2, y2)) {
				printf("Move ok!\n");
			} else {
				printf("Move failed!\n");
				break;
			}
		} else {
			printf("find solution failed!\n");
			break;
		}
	}

	return 0;

}
